﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using YSC_Core.BLL.Domain.Entity;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_Backstage_Web.Controllers
{
    /// <summary>
    /// 活动文章管理
    /// </summary>
    public class NewsArticleController : Controller
    {
        private readonly IBasisBackstageServices _pro;
        public NewsArticleController(IBasisBackstageServices pro)
        {
            _pro = pro;
        }

        /// <summary>
        /// 活动列表
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 活动新增
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 文章列表
        /// </summary>
        /// <returns></returns>
        public IActionResult NewsList()
        {
            return View();
        }

        //活动添加
        public IActionResult Edit(string Id)
        {
            var aa = _pro.GetNewsArticle(Id);
            var json = JsonConvert.SerializeObject(aa.Result);
            JObject obj = JObject.Parse(json);
            NewsArticle entity = JsonConvert.DeserializeObject<NewsArticle>(obj["Data"].ToString());
            return View(entity);
        }

        /// <summary>
        /// 活动图上传
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public IActionResult ImportHeadDiagram(string guid, string type)
        {
            ViewData["guid"] = guid;
            ViewData["type"] = type;
            return View();
        }


        public JsonResult GetNewsArticleAll(int limit, int page, string keyword)
        {
            var result = _pro.GetNewsArticleAll(page, limit, keyword, "新闻动态");
            return Json(result);
        }

        /// <summary>
        /// 活动列表
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public JsonResult GetList(int limit, int page, string keyword)
        {
            var result = _pro.GetNewsArticleAll(page, limit, keyword, "活动");
            return Json(result);
        }

        public JsonResult AddEditSubmit(string paramete)
        {
            NewsArticle entity = JsonConvert.DeserializeObject<NewsArticle>(paramete);
            entity.Type = "活动";
            var result = _pro.AddUpdateNewsArticle(entity);
            return Json(result);
        }


        public JsonResult GetUpdateStatusById(string Id, string Type)
        {
            var result = _pro.GetUpdateStatusById(Id, Type);
            return Json(Type);
        }

    }
}